package com.aube.dream;

import android.annotation.TargetApi;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.os.Build;
import android.support.multidex.MultiDex;

import com.aube.AubeApplicationLikeHelper;
import com.aube.tinker.MyLogImp;
import com.aube.tinker.TinkerManager;
import com.aube.video.ad.VideoAdHelper;
import com.huyn.baseframework.share.QQUtil;
import com.huyn.baseframework.share.WeiboConstants;
import com.huyn.baseframework.utils.Constant;
import com.tencent.tinker.anno.DefaultLifeCycle;
import com.tencent.tinker.lib.tinker.TinkerInstaller;
import com.tencent.tinker.loader.app.DefaultApplicationLike;
import com.tencent.tinker.loader.shareutil.ShareConstants;

/**
 * Created by huyaonan on 16/11/9.
 */
@SuppressWarnings("unused")
@DefaultLifeCycle(application = "com.aube.dream.LaunchBaseApplication",
        flags = ShareConstants.TINKER_ENABLE_ALL,
        loadVerifyFlag = false)
public class LaunchApplicationLike extends DefaultApplicationLike {
    public LaunchApplicationLike(Application application, int tinkerFlags, boolean tinkerLoadVerifyFlag, long applicationStartElapsedTime, long applicationStartMillisTime, Intent tinkerResultIntent, Resources[] resources, ClassLoader[] classLoader, AssetManager[] assetManager) {
        super(application, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime, applicationStartMillisTime, tinkerResultIntent, resources, classLoader, assetManager);
    }

    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    @Override
    public void onBaseContextAttached(Context base) {
        super.onBaseContextAttached(base);
        //you must install multiDex whatever tinker is installed!
        MultiDex.install(base);

        TinkerManager.setTinkerApplicationLike(this);
        TinkerManager.initFastCrashProtect();
        //should set before tinker is installed
        TinkerManager.setUpgradeRetryEnable(true);

        //optional set logIml, or you can use default debug log
        TinkerInstaller.setLogIml(new MyLogImp());

        //installTinker after load multiDex
        //or you can put com.tencent.tinker.** to main dex
        TinkerManager.installTinker(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();

        new AubeApplicationLikeHelper().onCreate(getApplication(), "2882303761517531029", "5241753182029");

        //设置api相关key和微信的appid
//        Constant.setAppKeyAndSecret("youngdreams", "28f6d4bacaa5195591c6bf006d47a5ff", "wxbc91c2106e120747");
        Constant.setAppKeyAndSecret("youngdreams-android", "a81d152ba43c223b8aac0e0011b3e797", "wxbc91c2106e120747");

        //设置微博的key
        WeiboConstants.APP_KEY = "502537124";

        //设置广告id
        VideoAdHelper.setAdId("3036864", "3036848");

        //设置qq的key
        QQUtil.APP_ID = "1105866210";
    }

    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public void registerActivityLifecycleCallbacks(Application.ActivityLifecycleCallbacks callback) {
        getApplication().registerActivityLifecycleCallbacks(callback);
    }

}
